<?php
/**
 * @package Sj Virtue Mart
 * @version 2.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2012 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */
defined( '_JEXEC' ) or die;?>
 <div class="yt-vm-content">
		<div  class="vm-content-inner">
		<?php
		$item_class = '';
		$i = 0;
		foreach( $list as $key => $item ) :
		$i++;
		if ($key == 0) {
			$item_class = 'yt-first';
		} else if ($key == sizeof($list) - 1) {
			$item_class = 'yt-last';
		}
		if((int)$params->get('nb_cols', 3) <= 0){
			$params->set('nb_cols', 1);
		}
		if((int)$params->get('nb_rows', 3) <= 0){
			$params->set('nb_rows' ,1);
		}
		if($i%$options->nb_cols  == 1 || ($options->nb_cols == 1)) {
		?>
		 <div class="vm-row">	
		<?php }?> 
        	<div class="yt-item <?php echo $item_class?> vm-item">
				<div class="yt-main-content">
					
					<!-- For Item Image-->
					<?php if($options->item_image_display == 1):?>
					<div class="yt-item-image" style="width:<?php echo $options->item_image_width ?>px; height:<?php echo $options->item_image_height ?>px; overflow:hidden;">
						<?php
							if ( (int)$params->get('item_image_linkable', 0) ){?>
								<a href="<?php echo $item->link;?>" <?php echo YTools::parseTarget($options->item_link_target); ?> title="<?php echo $item->product_name; ?>" >
									<img src="<?php echo YTools::resize($item->images,$image_config); ?>" alt="<?php echo $item->product_name?>" title="<?php echo $item->product_name?>" />
								</a>
							<?php  } else { ?>
								<img src="<?php echo YTools::resize($item->images,$image_config); ?>" alt="<?php echo $item->product_name?>" title="<?php echo $item->product_name?>" />
							<?php }
						?>
					</div>
					<?php endif; ?>
					
					<?php if( $options->item_title_display == 1 ) : ?>
					<div class="yt-item-title">
						<?php if ($options->item_title_linkable==1){?>
								<a href="<?php echo $item->link; ?>" <?php echo YTools::parseTarget($options->item_link_target); ?> title="<?php echo $item->product_name; ?>">
									<?php 	echo Ytools::truncate($item->product_name,$options->item_title_max_characters);?>
								</a>
						<?php } else {  ?>
								<a>
									<?php 	echo Ytools::truncate($item->product_name,$options->item_title_max_characters);?>
								</a>
							<?php } ?>
					</div>
					<?php endif; ?>
					
					<div class="price-rating">
						<!-- For Item Price-->
						<?php if( (int)$params->get('item_price_display', 1) ): ?>
							<div class="sj_item_prices" >
							<?php
							//var_dump($item->product_rating);
							
								$currency = &CurrencyDisplay::getInstance();
								if ( !empty($item->prices['salesPrice']) ){
									echo $currency->createPriceDiv('salesPrice', 'Price: ', $item->prices);
								}
								if ( !empty($item->prices['salesPriceWithDiscount']) ){
									echo $currency->createPriceDiv('salesPriceWithDiscount', '', $item->prices, true);
								}
							?>
							</div>
						<?php endif;  ?>
						
						<?php
							if (!empty($item->product_rating)) {
								$maxrating = VmConfig::get('vm_maximum_rating_scale', 5);
					
								$ratingwidth = $item->product_rating * 13; //*24; //I don't use round as percetntage with works perfect, as for me
								?>
									<span class="vote">
										<span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . round($item->product_rating) . '/' . $maxrating) ?>" class="ratingbox" style="display:inline-block;">
											<span class="stars-orange" style="width:<?php echo $ratingwidth.'px'; ?>"></span>
										</span>
										<span class="vote-number">
											<?php //echo JText::_('COM_VIRTUEMART_RATING') . ' ' . round($item->product_rating) . '/' . $maxrating; ?>
											<?php if(round($item->product_rating)>1) echo '( '. round($item->product_rating) . ' Votes)'; else echo '( '. round($item->product_rating) . ' Vote)'; ?>
										</span>
									</span>
								<?php
							}
						?>
						
					</div>
					<!-- For Item Description-->
					<?php if($options->item_description_display):?>
					<div class="yt-item-desc">
					  <?php
						 	$desc = "";
							if(!empty($item->product_s_desc)){
								YTools::extractImages($item->product_s_desc);
								$desc = $item->product_s_desc;	
							}else{
								YTools::extractImages($item->product_desc);
								$desc = $item->product_desc;	
							}
							if ( (int)$params->get('item_description_striptags', 1) ){
								$keep_tags = $params->get('item_description_keeptags', '');
								$keep_tags = str_replace(array(' '), array(''), $keep_tags);
								$tmp_desc = strip_tags($desc ,$keep_tags );
								echo YTools::truncate($tmp_desc, (int)$params->get('item_description_max_characters'));
							} else {
								echo YTools::truncate($desc, (int)$params->get('item_description_max_characters'));
							}
						?>
					</div>
					<?php endif; ?>
					<!-- For Item Readmore-->
					<?php if($options->item_readmore_display == 1):?>
					<div class="yt-item-readmore">
						<a class="button1" href="<?php echo $item->link;?>" <?php echo YTools::parseTarget($options->item_link_target); ?> title="<?php echo $item->product_name; ?>" >
							<?php echo $options->item_readmore_text;?>
						</a>
						
						
						
						
						<div class="addtocart-area">
							<form method="post" class="product js-recalculate" action="<?php echo JRoute::_ ('index.php'); ?>">
								<?php // Product custom_fields
								if (!empty($item->customfieldsCart)) {
									?>
									<div class="product-fields">
										<?php foreach ($item->customfieldsCart as $field) { ?>
										<div class="product-field product-field-type-<?php echo $field->field_type ?>">
											<span class="product-fields-title-wrapper"><span class="product-fields-title"><strong><?php echo JText::_ ($field->custom_title) ?></strong></span>
											<?php if ($field->custom_tip) {
											echo JHTML::tooltip ($field->custom_tip, JText::_ ($field->custom_title), 'tooltip.png');
										} ?></span>
											<span class="product-field-display"><?php echo $field->display ?></span>
						
											<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
										</div><br/>
										<?php
									}
										?>
									</div>
									<?php
								}
								/* Product custom Childs
									 * to display a simple link use $field->virtuemart_product_id as link to child product_id
									 * custom_value is relation value to child
									 */
						
								if (!empty($item->customsChilds)) {
									?>
									<div class="product-fields">
										<?php foreach ($item->customsChilds as $field) { ?>
										<div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
											<span class="product-fields-title"><strong><?php echo JText::_ ($field->field->custom_title) ?></strong></span>
											<span class="product-field-desc"><?php echo JText::_ ($field->field->custom_value) ?></span>
											<span class="product-field-display"><?php echo $field->display ?></span>
						
										</div><br/>
										<?php } ?>
									</div>
									<?php }
						
								if (!VmConfig::get('use_as_catalog', 0) and !empty($item->prices['salesPrice'])) {
								?>
						
								<div class="addtocart-bar">
						
									<?php // Display the quantity box
						
									$stockhandle = VmConfig::get ('stockhandle', 'none');
									if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($item->product_in_stock - $item->product_ordered) < 1) { ?>
										<a href="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $item->virtuemart_product_id); ?>" class="notify"><?php echo JText::_ ('COM_VIRTUEMART_CART_NOTIFY') ?></a>
									<?php } else { ?>
										<?php
										// Display the add to cart button
										?>
										<span class="addtocart-button">
											<?php echo shopFunctionsF::getAddToCartButton ($item->orderable); ?>
										</span>
									
									<?php } ?>
						
									<div class="clear"></div>
								</div>
								<?php }
								 // Display the add to cart button END  ?>
								 
								<input type="hidden" name="quantity[]" value="<?php if (isset($item->min_order_level) && (int)$item->min_order_level > 0) {
												echo $item->min_order_level;
											} else {
												echo '1';
											} ?>"/>
								<input type="hidden" class="pname" value="<?php echo htmlentities($item->product_name, ENT_QUOTES, 'utf-8') ?>"/>
								<input type="hidden" name="option" value="com_virtuemart"/>
								<input type="hidden" name="view" value="cart"/>
								<noscript><input type="hidden" name="task" value="add"/></noscript>
								<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $item->virtuemart_product_id ?>"/>
							</form>
						
							<div class="clear"></div>
						</div><!--end add to card-->
						
						
						
					</div>
					<?php endif; ?>
				</div>
               </div>
               <?php if($i%$options->nb_cols == 0 || $i == count($list)){?>
				<div class="clear"></div>
				</div>
			  <?php } ?>
        <?php endforeach; ?>
        <div class="clear"></div>
	  </div>
	    <div class="clear"></div>
   </div>